if(FALSE){
  y2011 <- SS_readdat('c:/SS/SSv3.3/YelloweyeRF_2011/yelloweye_data.SS')
  y2011_3.3 <- convert_to_SS3.3(y2011)
  SS_writedat3.3(y2011_3.3, "c:/SS/SSv3.3/YelloweyeRF_2011_3.3/yelloweye_data.SS",
                 overwrite=TRUE)

  three_area <- SS_readdat('c:/SS/SSv3.3/three_area/three_area_dat.SS')
  three_area_3.3 <- convert_to_SS3.3(three_area)
  three_area_forecast <- SS_readforecast('c:/SS/SSv3.3/three_area/forecast.ss',
                                         Nfleets=three_area$Nfleet,
                                         Nareas=three_area$N_areas)
  three_area_3.3_forecast <- three_area_forecast
  three_area_3.3_forecast$Nfleets <- three_area_3.3$Nfleet
  three_area_3.3_forecast$max_totalcatch_by_fleet <- rep(-1,three_area_3.3$Nfleet)
  three_area_3.3_forecast$fleet_assignment_to_allocation_group <- rep(0,three_area_3.3$Nfleet)
  SS_writedat3.3(three_area_3.3, "c:/SS/SSv3.3/three_area_3.3/three_area_dat.SS",
                 overwrite=TRUE)
  SS_writeforecast(three_area_3.3_forecast,dir="c:/SS/SSv3.3/three_area_3.3/",overwrite=TRUE)

  Simple <- SS_readdat('c:/SS/SSv3.3/Simple/simple.dat')
  Simple_3.3 <- convert_to_SS3.3(Simple)
  Simple_forecast <- SS_readforecast('c:/SS/SSv3.3/Simple/forecast.ss',
                                         Nfleets=Simple$Nfleet,
                                         Nareas=Simple$N_areas)
  Simple_3.3_forecast <- Simple_forecast
  Simple_3.3_forecast$Nfleets <- Simple_3.3$Nfleet
  Simple_3.3_forecast$max_totalcatch_by_fleet <- rep(-1,Simple_3.3$Nfleet)
  Simple_3.3_forecast$fleet_assignment_to_allocation_group <- rep(0,Simple_3.3$Nfleet)
  SS_writedat3.3(Simple_3.3, "c:/SS/SSv3.3/Simple_3.3/simple.dat",
                 overwrite=TRUE)
  SS_writeforecast(Simple_3.3_forecast,dir="c:/SS/SSv3.3/Simple_3.3/",overwrite=TRUE)

}

convert_to_SS3.3 <- function(dat1){
  # dat1 is in old format
  #dat1 <- SS_readdat('c:/SS/SSv3.3/SS3.24/Simple_Dat_2.dat')
  
  # dat2 is in new format
  dat2 <- dat1
  Nfleet <- dat1$Nfleet
  Nsurveys <- dat1$Nsurveys
  Ntypes <- Nfleet + Nsurveys
  # reorder the catch
  dat2$catch <- dat1$catch[,c(Nfleet+1:2, 1:Nfleet)]
  # add initial equilibrium to main catch matrix
  equil_catch_total <- NULL
  for(iseas in 1:dat1$nseas){
    equil_catch <- dat2$catch[1,]  # copy first row of catch
    equil_catch$year <- -999  # change year to -999
    equil_catch$seas <- iseas # season
    # fill in values only for season 1
    if(iseas==1) equil_catch[1,-(1:2)] <- dat1$init_equil
    # add to all previous seasons
    equil_catch_total <- rbind(equil_catch_total,equil_catch)
  }
  dat2$catch <- rbind(equil_catch_total, # put equilibrium at top of catch matrix
                      dat2$catch)
  # add zero column for each survey
  if(Nsurveys>0){
    for(i in 1:Nsurveys){
      dat2$catch <- data.frame(dat2$catch, 0)
    }
  }
  names(dat2$catch) <- c("year","seas",dat1$fleetnames)
  dat2$N_catch <- nrow(dat2$catch)
  

  #_fleet_type: 1=catch fleet; 2=bycatch only fleet; 3=survey; 4=ignore 
  #_survey_timing: -1=for use of catch-at-age; fraction for fraction of season (0.5 for mid-season); does not affect ALK timing (always midseason) 
  #_fleet_area:  area the fleet/survey operates in 
  #_units of catch:  1=bio; 2=num (ignored for surveys; their units read later)
  #_equ_catch_se:  standard error of log(initial equilibrium catch)
  #_catch_se:  standard error of log(catch); can be overridden in control file with detailed F input
  #_rows are fleets; columns are: fleet_type, timing, area, units, equ_catch_se, catch_se

  dat2$fleetinfo <-
    data.frame(# define fishery vs. survey
               fleet_type=c(rep(1,Nfleet),rep(3,Nsurveys)),
               # timing and area are from first block
               timing=as.numeric(dat1$fleetinfo1[1,1:Ntypes]),
               area=as.numeric(dat1$fleetinfo1[2,1:Ntypes]),
               # next quantities were previously only for fisheries
               # setting survey catch to default as units of biomass
               units=c(as.numeric(dat1$fleetinfo2[1,1:Nfleet]),
                 rep(1,Nsurveys)),
               equ_catch_se=c(as.numeric(dat1$fleetinfo2[2,1:Nfleet]),
                 rep(0,   Nsurveys)),
               catch_se=c(as.numeric(dat1$fleetinfo2[2,1:Nfleet]),
                 rep(0,   Nsurveys)))

  dat2$read_seas_month <- 1 #(1=read seas; 2=read month)
  dat2$SSversion <- "SS-V3.30a-safe;_03/21/2013"
  dat2$Nfleet <- Ntypes
  dat2$N_subseasons <- 2 # copying Rick's example. Setting to 1 would probably give closer match.

  dat2$agecompinfo <-
    data.frame(mintailcomp  = rep(dat1$comp_tail_compression,Ntypes),
               addtocomp    = rep(dat1$add_to_comp,          Ntypes),
               combMplusF   = rep(dat1$max_combined_age,     Ntypes),
               CompressBins = rep(0,                         Ntypes))

  dat2$lencompinfo <-
    data.frame(mintailcomp  = rep(dat1$comp_tail_compression,Ntypes),
               addtocomp    = rep(dat1$add_to_comp,          Ntypes),
               combMplusF   = rep(dat1$max_combined_lbin,    Ntypes),
               CompressBins = rep(0,                         Ntypes))

  #SS_writedat3.3(dat2,'c:/SS/SSv3.3/SS3.3.test2/test_writedat3.3.dat',overwrite=TRUE)
  return(dat2)
}
